package org.tis.tools.abf.module.om.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.tis.tools.abf.module.om.controller.request.OmBatchDeleteRequest;
import org.tis.tools.abf.module.om.dao.OmGroupAppMapper;
import org.tis.tools.abf.module.om.entity.OmGroupApp;
import org.tis.tools.abf.module.om.exception.OMExceptionCodes;
import org.tis.tools.abf.module.om.exception.OrgManagementException;
import org.tis.tools.abf.module.om.service.IOmGroupAppService;
import org.tis.tools.core.utils.StringUtil;

import static org.tis.tools.core.utils.BasicUtil.wrap;

/**
 * omGroupApp的Service接口实现类
 * 
 * @author Auto Generate Tools
 * @date 2018/04/23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OmGroupAppServiceImpl extends ServiceImpl<OmGroupAppMapper, OmGroupApp> implements IOmGroupAppService {

    @Override
    public void batchDelete(OmBatchDeleteRequest omBatchDeleteRequest) throws OrgManagementException {

        if (StringUtil.isEmpty(omBatchDeleteRequest.getGuid())){
            throw new OrgManagementException(OMExceptionCodes.PARMS_NOT_ALLOW_EMPTY,wrap("删除时参数列表为空"));
        }
        if (0 == omBatchDeleteRequest.getDeleteList().size()){
            throw new OrgManagementException(OMExceptionCodes.PARAMETER_IS_EMPTY_WHRN_BATCH_DELETE,wrap("删除时参数列表为空"));
        }

        Wrapper<OmGroupApp> wrapper = new EntityWrapper<OmGroupApp>();
        wrapper.eq(OmGroupApp.COLUMN_GUID_GROUP,omBatchDeleteRequest.getGuid());
        wrapper.in(OmGroupApp.COLUMN_GUID_APP,omBatchDeleteRequest.getDeleteList());
        delete(wrapper);
    }
}

